// Copyright 2020 Leyantech Ltd. All Rights Reserved.

package com.leyantech.ecp.agenx.web.testwin;

import com.leyantech.ecp.agenx.common.utils.PbPrintHelper;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

/**
 * @author jackie, {@literal <xucheng.xie@leyantech.com>}
 * @date 2020-09-04.
 */

public class TestWinJsonAdapter extends TypeAdapter<TestWinReply> {

  @Override
  public void write(JsonWriter jsonWriter, TestWinReply testWinReply) throws IOException {
    JsonWriter writer = jsonWriter.beginObject();
    if (testWinReply.getDialogueReplyV2() != null) {
      writer.name("dialogue_reply_v2")
          .jsonValue(PbPrintHelper.toJson(testWinReply.getDialogueReplyV2()));
    }
    if (testWinReply.getDialogueReplyContext() != null) {
      writer.name("dialogue_context")
          .jsonValue(PbPrintHelper.toJson(testWinReply.getDialogueReplyContext()));
    }
    if (testWinReply.getPolicyDetail() != null) {
      writer.name("policy_detail").jsonValue(PbPrintHelper.toJson(testWinReply.getPolicyDetail()));
    }
    if (testWinReply.getFaqDetail() != null) {
      writer.name("faq_detail").jsonValue(PbPrintHelper.toJson(testWinReply.getFaqDetail()));
    }
    if (testWinReply.getWorkFlowDetail() != null) {
      writer.name("work_flow_detail").jsonValue(PbPrintHelper.toJson(testWinReply.getWorkFlowDetail()));
    }
    if (testWinReply.getH2HDetail() != null) {
      writer.name("h2h_detail").jsonValue(PbPrintHelper.toJson(testWinReply.getH2HDetail()));
    }
    if (testWinReply.getWaitDetail() != null) {
      writer.name("wait_detail").jsonValue(PbPrintHelper.toJson(testWinReply.getWaitDetail()));
    }
    if (testWinReply.getTimestamp() != null) {
      writer.name("time_stamp").value(testWinReply.getTimestamp());
    }
    writer.endObject();
  }

  @Override
  public TestWinReply read(JsonReader jsonReader) throws IOException {
    //testwin暂时没有反序列化的需求
    return null;
  }
}
